<?php

namespace backend\models;

use yii\base\Model;

class DeliveryinfoForm extends Model {
	
	//表单属性
	public $deliveryName;   //物流商名
	public $deliveryAb;     //物流商助记码
	public $address;   	    //地址
	public $linkName;   	//联系人
	public $linkTel;        //联系电话
	public $qq;   			//qq
	public $email;   		//邮箱	
	public $state;   		//启用状态
	
	
	//表单规则
	public function rules(){
		
		return [
		
			//添加规则
			[['deliveryName','address','linkName','linkTel'],'required','message'=>'{attribute}不能为空','on'=>'add'],
			['deliveryName','string','on'=>'add','max'=>10,'tooLong'=>'物流商名太长'],
			['linkTel','integer','message'=>'电话格式不正确','on'=>'add',],
			['qq','integer','on'=>'add','message'=>'QQ格式不正确',],
			['email','email','on'=>'add','message'=>'邮箱格式不正确',],
		];
		
	}
	
	
	//自定义验证规则
	public  function validateTel($attribute,$paramars){
		
		//如果没有错误则进行下面的验证
		if(!$this->hasErrors()){
			if( !is_numeric($this->linkTel))
				return $this->addError($attribute,'电话号码只能为数字类型');
			if($this->linkTel == '' || $this->num == 0 )
				return $this->addError($attribute,'联系电话不能为空或0');				
		}
	}
	
	
	//表单场景
	public function scenarios(){
		
		return [
			'add'=>['deliveryName','deliveryAb','address','linkName','linkTel','qq','email','state'],
		];
		
	}
	
	
	//表单属性标签
	public function attributeLabels(){
		return [
			'deliveryName'=>'物流商名',
			'deliveryAb'=>'物流商助记码',
			'address'=>'地址',
			'linkName'=>'联系人',
			'linkTel'=>'联系电话',						
			'qq'=>'QQ',
			'email'=>'电子邮箱',
			'state'=>'是否启用',
		
		];
	}
	
	
	
}

?>